<template>
  <div class="wrap">
    <div class="block">
      <el-form class="form">
        <h1 style="display: block;margin: auto">F Blog</h1>

        <el-form-item label="用户名" label-width="100px">
          <el-input v-model="user.userName"></el-input>
        </el-form-item>

        <el-form-item label="密码" label-width="100px">
          <el-input type="password" v-model="user.userPassword"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="success" v-text="'登录'" @click="login"></el-button>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>

<script>
import {login} from '../../request/request'

export default {
  data() {
    return {
      user: {
        userName: 'mucd01',
        // uerEmail: '',
        userPassword: '123456',
      }
    };
  },

  methods: {
    login() {

      this.$request.login(this.user).then((data) => {
        if (data.code !== 200) {
          this.$message.error(data.msg)
          return
        }

        //存储token
        localStorage.setItem('token', data.data)
        localStorage.setItem('user', this.user.userName)
        this.$message.success('登陆成功')

        this.$router.replace('/blogHome')
      })
    },
  },

  name: "UserLogin",
};
</script>

<style scoped>
.form {
  /*width: 33%;*/
  /*margin: auto;*/
}

.block {
  width: 100%;
  height: 230px;
  background-color: rgba(66, 180, 142, 0.36);
  border-radius: 10px;
}

</style>
